<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>求和</title>

	<script type="text/javascript">
        window.onload=function(){
        	//获取元素
        	var oTxt1 = document.getElementById('txt1');
        	var oTxt2 = document.getElementById('txt2');
        	var oBtn = document.getElementById('btn1');

            //点击事件
            oBtn.onclick = function(){
           	   
                var n1 = parseInt(oTxt1.value);
                var n2 = parseInt(oTxt2.value);

                //用isNaN判断输入的是否是数字
                if(isNaN(n1)){
                	alert('您输入的第一个数字有误');
                }else if(isNaN(n2)){
                	alert('您输入的第二个数字有误');
                } 

                alert(n1+n2);
            }
        }


	</script>
</head>

<body>

    <input type="text" id="txt1">
    <input type="text" id="txt2">
    <input type="button" id="btn1" value="求和">
	
</body>
</html>